/*** 
 * @Author: Yanan Chen
 * @Date: 2021-11-02 13:47:03
 * @LastEditTime: 2021-11-19 14:13:07
 * @LastEditors: Yanan Chen
 * @Description: 
 * @FilePath: \sadwinner\fw\esp32\Src\APP\app_button.h
 * @
 */
#ifndef PRJ_APP_BUTTON_H
#define PRJ_APP_BUTTON_H


#define BUTTON_EVT_DEEP 10


#define BUTTON_PRESS        0x22
#define BUTTON_RELEASE      0x33
#define BUTTON_KEEPTIM_MIN  30
#define BUTTON_KEEPTIM_MAX  8000
#define BUTTON_KEEPTIM_WAIT_MAX  400
#define BUTTON_KEEPTIM_FORSHORT_MIN  100
#define BUTTON_KEEPTIM_FORSHORT_MAX  1000
#define BUTTON_KEEPTIM_FORLONG_MIN  3000



typedef enum 
{
    ButtonType_EMPTY,
    ButtonType_SHORT,
    ButtonType_LONG,
    ButtonType_CONTINUE,
}ButtonType;

enum class ButtonNUM
{
    UP,
    DOWN,
    TOUCH,
    MAX,
};

typedef struct 
{
   char io;
   char press_val;
}HARDWARE_BUTTON_HANDLE;

typedef struct 
{
    int timecnt;
    int samplewait;
    int samplecnt;
    char last_status;
}IOButtonInfo;


typedef struct 
{
    char key;
    ButtonType type;
    char val;
}ButtonEVT;

class AppButton
{
public:
    AppButton();
    ~AppButton(){};
    void run(int time);
    ButtonEVT getButtonEVT();
private:
    static void touch_pad_check(int time);
    static void mpu_virtual_button_check(int time);
    static void hardware_button_check(int time);
    ButtonEVT evt[BUTTON_EVT_DEEP];
    char init_flag;
    void init();
};



#endif